home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / LIFER__ / PROTO / P / PMD_LIFE.C < prev    next >
Text File  |  1991-07-23  |  11KB  |  272 lines

  1. /* PMD_LIFE_WINDOW */
  2.  
  3. /* File name: LIFE_WINDOW */
  4. /* Function: Handle a modeless dialog */
  5. /*           This dialog operates like a window, it is not modal. */
  6. /*           Opened by:       */
  7. /*           Closed by:       */
  8. /*           Purpose:       */
  9. /* History: 7/23/91 Original by Prototyper 3.0   */
  10.  
  11.  
  12. #include "PCommonLife.h"    /* Common */
  13. #include "Common_Life.h"    /* Common */
  14. #include "PUtils_Life.h"    /* General Utilities */
  15. #include "Utils_Life.h"    /* General Utilities */
  16.  
  17. #include "PA_Life_Alert.h"    /* Alert */
  18. #include "PD_LIFE_INPUT.h"    /* Modal Dialog */
  19. #include "LIFE_WINDOW.h"    /* This specific modeless dialog */
  20. #include "PMD_LIFE_WINDOW.h"    /* This modeless dialog */
  21.  
  22.  
  23.  
  24. static Boolean        ExitDialog;                                             /* Flag to exit dialog */
  25.  
  26.  
  27. /* ======================================================= */
  28.  
  29.  
  30.  
  31.  
  32. /* ======================================================= */
  33.  
  34.  
  35. /* This procedures purpose is to set the window pointer to nil, */
  36. /* this is used to tell the other routines in this unit that this */
  37. /* modeless dialog is not yet active (open).  The other routines */
  38. /* will then just return when called, without doing anything. */
  39. void Init_LIFE_WINDOW()
  40. {
  41.         Rect    tempRect;                                                     /* Temporary rectangle */
  42.         short    DType;                                                         /* Type of dialog item */
  43.         short    Index;                                                         /* For looping */
  44.         Handle    DItem;                                                        /* Handle to the dialog item */
  45.         ControlHandle    CItem, CTempItem;                                /* Control handle */
  46.         Str255    sTemp;                                                     /* Get text entered, temp holding */
  47.         short    itemHit;                                                       /* Get selection */
  48.         short    temp;                                                          /* Get selection, temp holding */
  49.  
  50.         WPtr_LIFE_WINDOW = NIL;                                          /* Initialize to say that the dialog is not yet active */
  51.  
  52.  
  53.         U_Init_LIFE_WINDOW();                                              /* Call the user init routine */
  54.  
  55. }
  56.  
  57.  
  58. /* ======================================================= */
  59.  
  60. /* Routine: Moved_LIFE_WINDOW */
  61. /* Purpose: We were moved, possibly to another screen and screen depth */
  62.  
  63. void Moved_LIFE_WINDOW(OldRect, theWindow)                        /* Moved this window */
  64. Rect        *OldRect;
  65. WindowPtr    theWindow;
  66. {
  67.         WindowPtr    SavePort;                                              /* Place to save the last port */
  68.  
  69.         if (WPtr_LIFE_WINDOW == theWindow)                            /* Only do if the window is us */
  70.             {
  71.                 GetPort(&SavePort);                                          /* Save the current port */
  72.                 SetPort(WPtr_LIFE_WINDOW);                                /* Set the port to my window */
  73.  
  74.                 U_Moved_LIFE_WINDOW(WPtr_LIFE_WINDOW,OldRect);/* Call user routine when we are moved */
  75.                 SetPort(SavePort);                                             /* Restore the old port */
  76.             }                                                                      /* End for window is us */
  77. }                                                                                /* End of procedure */
  78.  
  79.  
  80. /* ======================================================= */
  81.  
  82.  
  83. /* This procedures purpose is to refresh this window, update it, */
  84. /* when we are uncovered by another window.  All of the non-controls */
  85. /* are in this routine, such as rectangles and lines.  Note that the */
  86. /* Open routine calls this one to draw all of the non-controls. */
  87. void Update_LIFE_WINDOW(theWindow)
  88. WindowPtr    theWindow;
  89. {
  90.         GrafPtr    SavedPort;                                                 /* Save the current port so we can restore to it */
  91.         Rect    tempRect;                                                     /* Temporary rectangle variable */
  92.         short    DType;                                                         /* Type of dialog item */
  93.         Handle    DItem;                                                        /* Handle to the dialog item */
  94.         ControlHandle    CItem;                                               /* Control handle */
  95.  
  96.  
  97.  
  98.         if ((WPtr_LIFE_WINDOW != NIL) && (theWindow == WPtr_LIFE_WINDOW))/* Only do if we are the window to update */
  99.             {                                                                      /* Start the update procedure */
  100.                 GetPort(&SavedPort);                                         /* Get the current port */
  101.                 SetPort(WPtr_LIFE_WINDOW);                                /* Point to our port for drawing in our window */
  102.  
  103.                 GetDItem(WPtr_LIFE_WINDOW,Res_Dlg_Continue,&DType,&DItem,&tempRect);/* Get the item handle */
  104.                 PenSize(3, 3);                                                  /* Change pen to draw thick default outline */
  105.                 InsetRect(&tempRect, -4, -4);                               /* Draw outside the button by 1 pixel */
  106.                 FrameRoundRect(&tempRect, 16, 16);                      /* Draw the outline */
  107.                 PenSize(1, 1);                                                  /* Restore the pen size to the default value */
  108.  
  109.                 /* Draw a line, Drawn line1  */
  110.                 PenSize(2,2);                                                   /* Set a wider pen width */
  111.                 MoveTo(0,100);                                                /* Horz,vert, Move to starting position */
  112.                 LineTo(179,100);                                              /* Horz,vert, Draw to the ending position */
  113.                 PenSize(1,1);                                                   /* Back to default pen size */
  114.  
  115.                 U_Update_LIFE_WINDOW(WPtr_LIFE_WINDOW);            /* Call the user update routine */
  116.  
  117.                 DrawDialog(WPtr_LIFE_WINDOW);                           /* Draw the rest of the controls */
  118.                 SetPort(SavedPort);                                           /* Restore the port that we saved at the start */
  119.             }                                                                      /* End for the IF saying we are the window to update */
  120. }                                                                                /* End for the update procedure */
  121.  
  122.  
  123. /* ======================================================= */
  124.  
  125.  
  126. /* This procedures purpose is to open this window and set all */
  127. /* of the initial conditions, such as default edit text.  This routine */
  128. /* calls the update routine to draw all non-controls.  If this */
  129. /* routine is already open when it is called again, then nothing */
  130. /* is done (another copy is NOT opened). */
  131. void Open_LIFE_WINDOW()
  132. {
  133.         TEHandle    ThisEditText; 
  134.         DialogPeek        TheDialogPtr;
  135.         Rect    tempRect;                                                     /* Temporary rectangle variable */
  136.         short    DType;                                                         /* Type of dialog item */
  137.         Handle    DItem;                                                        /* Handle to the dialog item */
  138.         ControlHandle    CItem;                                               /* Control handle */
  139.  
  140.  
  141.  
  142.         if (WPtr_LIFE_WINDOW == NIL)
  143.             {
  144.  
  145.                 WPtr_LIFE_WINDOW = GetNewDialog(Res_MD_LIFE_WINDOW, NIL,  (Ptr)-1 );/* Bring in the dialog resource */
  146.                 tempRect = WPtr_LIFE_WINDOW->portRect;                /* Get window size, we will now center it */
  147.                 tempRect.top = ((screenBits.bounds.bottom - screenBits.bounds.top) - (tempRect.bottom - tempRect.top)) / 2;/* Center vert */
  148.                 tempRect.left = ((screenBits.bounds.right - screenBits.bounds.left) - (tempRect.right - tempRect.left)) / 2;/* Center Horz */
  149.                 MoveWindow(WPtr_LIFE_WINDOW, tempRect.left, tempRect.top, TRUE);/* Now move the window to the proper position */
  150.                 ShowWindow(WPtr_LIFE_WINDOW);                         /* Open a dialog box */
  151.                 SelectWindow(WPtr_LIFE_WINDOW);                         /* Lets see it */
  152.                 SetPort(WPtr_LIFE_WINDOW);                                /* Prepare to add conditional text */
  153.                 TheDialogPtr = (DialogPeek)WPtr_LIFE_WINDOW;         /* Get to the inner record */
  154.                 ThisEditText = TheDialogPtr->textH;                        /* Get to the TE record */
  155.                 HLock((Handle)ThisEditText);                                 /* Lock it for safety */
  156.                 (*ThisEditText)->txSize = 12;                               /* TE Point size */
  157.                 TextSize(12);                                                   /* Window Point size */
  158.                 (*ThisEditText)->txFont = systemFont;                     /* TE Font ID */
  159.                 TextFont(systemFont);                                         /* Window Font ID */
  160.                 (*ThisEditText)->txFont = 0;                                 /* TE Font ID */
  161.                 (*ThisEditText)->fontAscent = 12;                         /* Font ascent */
  162.                 (*ThisEditText)->lineHeight = 12 + 3 + 1;                 /* Font ascent + descent + leading */
  163.                 HUnlock((Handle)ThisEditText);                              /* UnLock the handle when done */
  164.  
  165.  
  166.                 /* Setup initial conditions */
  167.  
  168.                 U_Setup_LIFE_WINDOW(WPtr_LIFE_WINDOW);             /* Call the user Open procedure */
  169.  
  170.             }
  171.         else
  172.                 SelectWindow(WPtr_LIFE_WINDOW);                         /* Lets see it */
  173. }                                                                                /* End of the Open procedure */
  174.  
  175.  
  176.  
  177. /* ======================================================= */
  178.  
  179.  
  180. /* This procedures purpose is to close this window and clear */
  181. /* the window pointer variable, this tells the other routines */
  182. /* that this window is closed and may be opened again. */
  183. void Close_LIFE_WINDOW(theWindow)
  184. WindowPtr    theWindow;
  185. {
  186.  
  187.         if ((theWindow ==  WPtr_LIFE_WINDOW) && (WPtr_LIFE_WINDOW != NIL ))/* Only close if it is us and we were open */
  188.             {                                                                      /* Start the close */
  189.  
  190.                 U_Close_LIFE_WINDOW(WPtr_LIFE_WINDOW);             /* Call the user close routine */
  191.  
  192.                 DisposDialog(WPtr_LIFE_WINDOW);                          /* Close on the screen and Flush the dialog out of memory */
  193.                 WPtr_LIFE_WINDOW = NIL;                                    /* Make sure our other routines know that we are closed */
  194.  
  195.  
  196.             }                                                                      /* End for the If saying it is us */
  197.  
  198. }                                                                                /* End for the close routine */
  199.  
  200.  
  201. /* ======================================================= */
  202.  
  203.  
  204. /* This procedures purpose is to handle all actions, such as buttons */
  205. /* being pressed.  This is the real meat of this unit and is where the */
  206. /* code is for acting upon the users actions. */
  207. void Do_LIFE_WINDOW(theEvent, theWindow,itemHit)
  208. EventRecord    *theEvent;
  209. WindowPtr    theWindow;
  210. short    itemHit;
  211. {
  212.         short    Index;                                                         /* For looping */
  213.         Point    myPt;                                                         /* For the local mouse position */
  214.         Boolean    ExitDialog;                                                 /* Flag to close this dialog */
  215.         short    DType;                                                         /* Type of dialog item */
  216.         Handle    DItem;                                                        /* Handle to the dialog item */
  217.         Rect    tempRect;                                                     /* Temporary rectangle */
  218.         ControlHandle    CItem;                                               /* Control handle */
  219.         short    temp;                                                          /* temp integer */
  220.  
  221.  
  222.  
  223.         ExitDialog = FALSE;                                                   /* Do not close the dialog yet */
  224.         if ((theEvent->what == mouseDown) && (WPtr_LIFE_WINDOW != NIL ))
  225.             {
  226.                 SetPort(WPtr_LIFE_WINDOW);                                /* Set the port to our dialog */
  227.                 myPt = theEvent->where;                                     /* Get the position where the mouse was pressed */
  228.                 GlobalToLocal(&myPt);                                        /* Change from global to local location */
  229.  
  230.              }
  231.  
  232.         if (WPtr_LIFE_WINDOW != NIL)
  233.             {
  234.                 if (theEvent->what == keyDown)
  235.                     {
  236.                         itemHit = 0;                                               /* Default to no item hit */
  237.                         temp = theEvent->message & charCodeMask;/* Get the character pressed */
  238.                         if ((temp == 13) || (temp == 3))                        /* See if CR or Enter */
  239.                             itemHit = 1;
  240.                     }
  241.  
  242.                 if ((WPtr_LIFE_WINDOW != NIL)  && (WPtr_LIFE_WINDOW  == theWindow))
  243.                     {
  244.                         myPt = theEvent->where;                              /* Get the position where the mouse was pressed */
  245.                         GlobalToLocal(&myPt);                                 /* Change from global to local location */
  246.                         GetDItem(WPtr_LIFE_WINDOW, itemHit,&DType,&DItem,&tempRect);/* Get which item was pressed */
  247.                         CItem = (ControlHandle)DItem;                         /* Change the pointer for getting to the control */
  248.  
  249.                         U_Hit_LIFE_WINDOW(WPtr_LIFE_WINDOW,itemHit,&ExitDialog,theEvent);/* Give the user the itemhit */
  250.  
  251.                         /* Handle it real time */
  252.                         if (itemHit ==Res_Dlg_Continue)                       /* Handle the Button being pressed */
  253.                             {
  254.                             }
  255.  
  256.                         if (itemHit ==Res_Dlg_Quit)                            /* Handle the Button being pressed */
  257.                             {
  258.                                 ExitDialog = TRUE;                                 /* Close this dialog, exit */
  259.                             }
  260.  
  261.  
  262.                     }                                                                /* End of not NIL */
  263.                    }
  264.                  
  265.                 if (ExitDialog == TRUE)                                         /* Do the close of the dialog */
  266.                     {
  267.                 Close_LIFE_WINDOW(WPtr_LIFE_WINDOW);
  268.                 WPtr_LIFE_WINDOW = NIL;                                    /* Clear it for future checks */
  269.             }
  270.         }                                                                          /* End of procedure */
  271.  
  272.